#!/bin/bash

# First, install packages:
# {{{ Package list
necessary_shit=(
anthy
emacs
etckeeper
git-completion
git-core
git-doc
gstreamer0.10-ffmpeg
gstreamer0.10-plugins-bad
gstreamer0.10-plugins-base
gstreamer0.10-plugins-good
gstreamer0.10-plugins-ugly
haskell-mode
htop
ibus-anthy
ipython
irssi
keychain
pidgin
python-mode
rxvt-unicode
screen
trayer
ttf-inconsolata
ttf-kochi-gothic
vim
whowatch
xautolock
xfonts-terminus
xlockmore
xmonad
xterm
)
# }}}

echo "Beginning package installation... "
sudo apt-get install ${necessary_shit[@]}

# Next, setup rc file links:
# {{{ Config files
rc_files=(
bash_profile
bashrc
conkyrc
emacs
emacs.d
gitconfig
inputrc
irssi
keychain
screenrc
ssh
vim
vimrc
xinitrc
Xmodmap
Xresources
xmonad
)
# }}}

for rc in ${rc_files[@]}; do

  # blow away pre-existing directories:
  # (mostly for pre-existing .emacs.d/, but .ssh/ could be a problem too...)
  if [ -d ${HOME}/.${rc} ]; then
    rm -rf ${HOME}/.${rc} && echo "Deleted existing ${rc} directory!"
  fi

  # replace stuff in the homedir with links to my config:
  ln -sf ${HOME}/config/.${rc} ${HOME}

done

# Explicitly create the .xsession link:
ln -sf ${HOME}/config/.xinitrc ${HOME}/.xsession

# No longer using awesome; don't need this section:
## Make sure awesome is properly configured too:
## rc.lua, theme.lua, vicious, and associated icons are all in here:
##mkdir -p ${HOME}/.config/awesome
##ln -sf ${HOME}/config/awesome ${HOME}/.config/

## NO, don't do this, since we're not trying to run awesome from within
## GNOME anymore, but via .Xsession
# Still disable the buggy Nautilus desktop thing
#gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop False
# sets awesome as wm
#gconftool-2 --type string --set /desktop/gnome/session/required_components/windowmanager awesome

# Nope, don't need this either:
## setup GDM properly for use w/ awesome:
##cp ${HOME}/config/xsession.desktop /tmp
##sudo cp /tmp/xsession.desktop /usr/share/xsessions

if [ ! -d ${HOME}/tmp ]; then
  echo "~/tmp must be a directory! Erasing it now..."
  rm -f ${HOME}/tmp
fi
mkdir -p ${HOME}/tmp

# Merge .Xresources (note that this must apparently be done within an xsession)
/usr/bin/xrdb -merge < ${HOME}/.Xresources

chmod 600 ${HOME}/.ssh/{oracle,id_rsa}

# TODO: add a line to start/init keychain, add .ssh/ keys?
# TODO: detect if I am a laptop, and fix scroll on middleclick
#sudo cat > /usr/lib/X11/xorg.conf.d/20-thinkpad.conf <<EOF
#Section "InputClass"
#	Identifier	"Trackpoint Wheel Emulation"
#	MatchProduct	"TPPS/2 IBM TrackPoint|DualPoint Stick|Synaptics Inc. Composite TouchPad / TrackPoint|ThinkPad USB Keyboard with TrackPoint|USB Trackpoint pointing device|Composite TouchPad / TrackPoint"
#	MatchDevicePath	"/dev/input/event*"
#	Option		"EmulateWheel"		"true"
#	Option		"EmulateWheelButton"	"2"
#	Option		"Emulate3Buttons"	"false"
#	Option		"XAxisMapping"		"6 7"
#	Option		"YAxisMapping"		"4 5"
#EndSection
#EOF

# echo "Remember to restart X to enable TrackPoint middle-button scrolling!"
